Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid

Imports Phoenix.DataAccess
Imports Phoenix.Helpers

Namespace Forms.Area

    Public Class ClientArea : Inherits GridAreaBase

        Public Event ClientSelectionChanged(ByVal sender As Object, ByVal args As EventArgs)

#Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
            GridView = ClientView
        End Sub

        'UserControl overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents GridControlClients As DevExpress.XtraGrid.GridControl
        Friend WithEvents ClientView As DevExpress.XtraGrid.Views.Grid.GridView
        Friend WithEvents ClientNameColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents ClientInOfficeColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents ClientInSalonRI As DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit
        Friend WithEvents ClientIconColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents ClientIconRI As DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
        Friend WithEvents ClientGenderColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents ClientGenderRI1 As DevExpress.XtraEditors.Repository.RepositoryItemComboBox
        Friend WithEvents ClientGenderRI As DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.GridControlClients = New DevExpress.XtraGrid.GridControl
            Me.ClientView = New DevExpress.XtraGrid.Views.Grid.GridView
            Me.ClientNameColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.ClientInOfficeColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.ClientInSalonRI = New DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit
            Me.ClientIconColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.ClientIconRI = New DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
            Me.ClientGenderColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.ClientGenderRI = New DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
            Me.ClientGenderRI1 = New DevExpress.XtraEditors.Repository.RepositoryItemComboBox
            CType(Me.GridControlClients, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ClientView, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ClientInSalonRI, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ClientIconRI, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ClientGenderRI, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ClientGenderRI1, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'GridControlClients
            '
            Me.GridControlClients.Dock = System.Windows.Forms.DockStyle.Fill
            '
            'GridControlClients.EmbeddedNavigator
            '
            Me.GridControlClients.EmbeddedNavigator.Name = ""
            Me.GridControlClients.Location = New System.Drawing.Point(0, 0)
            Me.GridControlClients.MainView = Me.ClientView
            Me.GridControlClients.Name = "GridControlClients"
            Me.GridControlClients.RepositoryItems.AddRange(New DevExpress.XtraEditors.Repository.RepositoryItem() {Me.ClientInSalonRI, Me.ClientIconRI, Me.ClientGenderRI1, Me.ClientGenderRI})
            Me.GridControlClients.Size = New System.Drawing.Size(368, 448)
            Me.GridControlClients.Styles.AddReplace("Style1", New DevExpress.Utils.ViewStyleEx("Style1", "", System.Drawing.SystemColors.Window, System.Drawing.SystemColors.WindowText, System.Drawing.Color.Empty, System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
            Me.GridControlClients.Styles.AddReplace("VertLine", New DevExpress.Utils.ViewStyleEx("VertLine", "Grid", "", True, False, False, DevExpress.Utils.HorzAlignment.Near, DevExpress.Utils.VertAlignment.Center, Nothing, System.Drawing.Color.Transparent, System.Drawing.Color.Transparent, System.Drawing.Color.Empty, System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
            Me.GridControlClients.Styles.AddReplace("FocusedCell", New DevExpress.Utils.ViewStyleEx("FocusedCell", "Grid", New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte)), CType((((((DevExpress.Utils.StyleOptions.StyleEnabled Or DevExpress.Utils.StyleOptions.UseBackColor) _
                                Or DevExpress.Utils.StyleOptions.UseDrawFocusRect) _
                                Or DevExpress.Utils.StyleOptions.UseFont) _
                                Or DevExpress.Utils.StyleOptions.UseForeColor) _
                                Or DevExpress.Utils.StyleOptions.UseImage), DevExpress.Utils.StyleOptions), System.Drawing.SystemColors.Highlight, System.Drawing.SystemColors.HighlightText, System.Drawing.SystemColors.InactiveCaption, System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
            Me.GridControlClients.Styles.AddReplace("CardCaption", New DevExpress.Utils.ViewStyleEx("CardCaption", "CardView", "", True, False, False, DevExpress.Utils.HorzAlignment.Near, DevExpress.Utils.VertAlignment.Center, Nothing, System.Drawing.SystemColors.InactiveCaption, System.Drawing.SystemColors.InactiveCaptionText, System.Drawing.Color.Empty, System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
            Me.GridControlClients.TabIndex = 2
            Me.GridControlClients.Text = "Clients"
            '
            'ClientView
            '
            Me.ClientView.Columns.AddRange(New DevExpress.XtraGrid.Columns.GridColumn() {Me.ClientNameColumn, Me.ClientInOfficeColumn, Me.ClientIconColumn, Me.ClientGenderColumn})
            Me.ClientView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.None
            Me.ClientView.GridControl = Me.GridControlClients
            Me.ClientView.Name = "ClientView"
            Me.ClientView.OptionsBehavior.AllowIncrementalSearch = True
            Me.ClientView.OptionsBehavior.ShowEditorOnMouseUp = True
            Me.ClientView.OptionsSelection.InvertSelection = True
            Me.ClientView.OptionsSelection.MultiSelect = True
            Me.ClientView.OptionsView.ShowGroupPanel = False
            Me.ClientView.OptionsView.ShowIndicator = False
            '
            'ClientNameColumn
            '
            Me.ClientNameColumn.Caption = "Name:"
            Me.ClientNameColumn.FieldName = "FullName"
            Me.ClientNameColumn.Name = "ClientNameColumn"
            Me.ClientNameColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.ClientNameColumn.SortIndex = 1
            Me.ClientNameColumn.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending
            Me.ClientNameColumn.VisibleIndex = 2
            Me.ClientNameColumn.Width = 302
            '
            'ClientInOfficeColumn
            '
            Me.ClientInOfficeColumn.Caption = "In"
            Me.ClientInOfficeColumn.ColumnEdit = Me.ClientInSalonRI
            Me.ClientInOfficeColumn.DisplayFormat.FormatString = "qqq %s"
            Me.ClientInOfficeColumn.FieldName = "InOffice"
            Me.ClientInOfficeColumn.MinWidth = 17
            Me.ClientInOfficeColumn.Name = "ClientInOfficeColumn"
            Me.ClientInOfficeColumn.Options = CType((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.ClientInOfficeColumn.SortIndex = 0
            Me.ClientInOfficeColumn.SortOrder = DevExpress.Data.ColumnSortOrder.Descending
            Me.ClientInOfficeColumn.VisibleIndex = 1
            Me.ClientInOfficeColumn.Width = 41
            '
            'ClientInSalonRI
            '
            Me.ClientInSalonRI.AutoHeight = False
            Me.ClientInSalonRI.Caption = ""
            Me.ClientInSalonRI.GlyphAlignment = DevExpress.Utils.HorzAlignment.Near
            Me.ClientInSalonRI.Name = "ClientInSalonRI"
            '
            'ClientIconColumn
            '
            Me.ClientIconColumn.ColumnEdit = Me.ClientIconRI
            Me.ClientIconColumn.FieldName = "Gender"
            Me.ClientIconColumn.Name = "ClientIconColumn"
            Me.ClientIconColumn.Options = CType(((DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly Or DevExpress.XtraGrid.Columns.ColumnOptions.FixedWidth) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.ClientIconColumn.VisibleIndex = 0
            Me.ClientIconColumn.Width = 23
            '
            'ClientIconRI
            '
            Me.ClientIconRI.AutoHeight = False
            Me.ClientIconRI.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.ClientIconRI.Items.AddRange(New Object() {New DevExpress.XtraEditors.Controls.ImageComboBoxItem("", "M", 7), New DevExpress.XtraEditors.Controls.ImageComboBoxItem("", "F", 30)})
            Me.ClientIconRI.Name = "ClientIconRI"
            '
            'ClientGenderColumn
            '
            Me.ClientGenderColumn.Caption = "Gender"
            Me.ClientGenderColumn.ColumnEdit = Me.ClientGenderRI
            Me.ClientGenderColumn.FieldName = "Gender"
            Me.ClientGenderColumn.Name = "ClientGenderColumn"
            Me.ClientGenderColumn.Options = CType((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.ClientGenderColumn.VisibleIndex = 3
            '
            'ClientGenderRI
            '
            Me.ClientGenderRI.AutoHeight = False
            Me.ClientGenderRI.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.ClientGenderRI.Items.AddRange(New Object() {New DevExpress.XtraEditors.Controls.ImageComboBoxItem("Male", "M", -1), New DevExpress.XtraEditors.Controls.ImageComboBoxItem("Female", "F", -1)})
            Me.ClientGenderRI.Name = "ClientGenderRI"
            '
            'ClientGenderRI1
            '
            Me.ClientGenderRI1.AutoHeight = False
            Me.ClientGenderRI1.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.ClientGenderRI1.Items.AddRange(New Object() {"Male", "Female"})
            Me.ClientGenderRI1.Name = "ClientGenderRI1"
            Me.ClientGenderRI1.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor
            '
            'ClientArea
            '
            Me.Controls.Add(Me.GridControlClients)
            Me.Name = "ClientArea"
            Me.Size = New System.Drawing.Size(368, 448)
            CType(Me.GridControlClients, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ClientView, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ClientInSalonRI, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ClientIconRI, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ClientGenderRI, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ClientGenderRI1, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)

        End Sub

#End Region

#Region " Event Handlers "
        Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            If DesignMode Then Return

            Me.GridControlClients.DataSource = New DataView(AppDataLayer.Clients)
        End Sub

        Private Sub ClientInSalonRI_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClientInSalonRI.EditValueChanged
            Try
                Me.ClientView.PostEditor()
                CurrentClient.EndEdit()

                ClientHelper.SwitchInOfficeStatus(CurrentClient, Me)

                CurrentClient.BeginEdit()
            Catch Ex As Exception
                Trace.WriteLineIf(AppError, Ex)
            End Try
            GridControlClients.Refresh()
        End Sub
#End Region

#Region " Area Behaviour "
        Public Overrides ReadOnly Property Icon() As DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
            Get
                Return ClientIconRI
            End Get
        End Property

        Public Overrides ReadOnly Property IconColumn() As DevExpress.XtraGrid.Columns.GridColumn
            Get
                Return ClientIconColumn
            End Get
        End Property


        Public Overrides Sub Paste(ByVal arr As IList)
            If arr Is Nothing Then
                Return
            End If
            For Each obj As DataRow In arr
                Dim item As DataAccess.DataSetData.Client = Helpers.ClientHelper.Copy(CType(obj, DataAccess.DataSetData.Client))
                Helpers.ClientHelper.UpdateClient(item, Me)
            Next
        End Sub

        Public Overrides Sub Delete(ByVal arr As IList)
            If arr Is Nothing Then Return

            Helpers.ClientHelper.DeleteClients(arr, Me)
        End Sub

#End Region

        Public Overrides Function CanCopy() As Boolean
            Return True
        End Function

        Public Overrides Function CanDelete() As Boolean
            Return Security.CanDeleteClient
        End Function


        Public ReadOnly Property CurrentClient() As DataSetData.Client
            Get
                If IsInvalidRowHandle(Me.ClientView.FocusedRowHandle) Then Return Nothing
                Dim eRowView As DataRowView = CType(ClientView.GetRow(ClientView.FocusedRowHandle), DataRowView)
                If eRowView Is Nothing Then Return Nothing
                Return eRowView.Row
            End Get
        End Property

        Private Sub ClientView_SelectionChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.SelectionChangedEventArgs) Handles ClientView.SelectionChanged
            RaiseEvent ClientSelectionChanged(Me, Nothing)
        End Sub
        Private Sub ClientView_FocusedRowChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles ClientView.FocusedRowChanged
            Dim rows() As Integer = ClientView.GetSelectedRows
            If Not rows Is Nothing Then
                For Each row As Integer In rows
                    ClientView.UnselectRow(row)
                Next
            End If

            ClientView.SelectRow(e.FocusedRowHandle)

        End Sub

    End Class

End Namespace
